package com.preskool.controller;

import com.preskool.service.EventsService;
import com.preskool.dto.ActionResult;
import com.preskool.po.Events;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther
 * @Date
 */
@RestController
@Slf4j
public class EventsController {

    @Autowired(required = false)
    private EventsService eventsService;

    //通过id查询单条信息
    @RequestMapping(value = "/selectEventsById",method = RequestMethod.GET)
    public ActionResult selectEventsById(int id){
        Events events = eventsService.selectEventsById(id);
        if (events!=null){
            return new ActionResult(200,"查询到了一条信息",events);
        }else{
            return new ActionResult(205,"没有查到",null);
        }
    }

    //添加大事记
    @RequestMapping(value = "addEvents",method = RequestMethod.POST)
    public ActionResult addEvents(@RequestBody Events events){
        System.out.println("要添加的数据:"+events);
        Boolean aBoolean = eventsService.addEvents(events);
        if (aBoolean==true){
            return new ActionResult(200,"添加成功",null);
        }else{
            return new ActionResult(205,"添加失败",null);
        }
    }

    //删除大事记
    @RequestMapping(value = "deleteEvents",method = RequestMethod.POST)
    public ActionResult deleteEvents(int id){
        Boolean aBoolean = eventsService.deleteEvents(id);
        if (aBoolean==true){
            return new ActionResult(200,"删除成功",null);
        }else{
            return new ActionResult(205,"删除失败",null);
        }
    }


    //修改大事记
    @RequestMapping(value = "updateEvents",method = RequestMethod.POST)
    public ActionResult updateEvents(@RequestBody Events events){
        Boolean aBoolean = eventsService.updateEvents(events);
        if (aBoolean==true){
            return new ActionResult(200,"修改成功",null);
        }else{
            return new ActionResult(205,"修改失败",null);
        }
    }
}
